<?
require_once("../config/dbconn.php");require_once("../config/powercls.php");
require_once("../config/pagecls.php");require_once("../config/usercls.php");
$sqlhy="select * from {$db_prefix}users where id='".$_SESSION['sys_userid']."'";
$rshy=$db->get_one($sqlhy);
$cxprice = $rshy["cxmoney"];

if($id=='1'){
	$username = $rshy["username"];
	$wp = 2000;
	if($cxprice<2000){
		echo "<script>alert('金额不足');history.back();</script>";exit();
	}
	$fenshu = 1;
	unset($dataArray);
	$dataArray["username"] = $username;
	$dataArray["wp"] = $wp;
	$dataArray["fenshu"] = $fenshu;
	$dataArray["state"] = 1;
	$dataArray['addtime']=$curtime;
	$dataArray['edittime']=0;
	$db->insert("{$db_prefix}cx",$dataArray);
	echo "<script>alert('已提交申请，请等待审核，审核通过后将自动扣取您的金额！');history.back();</script>";exit();
}
if($id=='2'){
	$username = $rshy["username"];
	$wp = 4000;
	if($cxprice<4000){
		echo "<script>alert('金额不足');history.back();</script>";exit();
	}
	$fenshu = 1;
	unset($dataArray);
	$dataArray["username"] = $username;
	$dataArray["wp"] = $wp;
	$dataArray["fenshu"] = $fenshu;
	$dataArray["state"] = 1;
	$dataArray['addtime']=$curtime;
	$dataArray['edittime']=0;
	$db->insert("{$db_prefix}cx",$dataArray);
	echo "<script>alert('已提交申请，请等待审核，审核通过后将自动扣取您的金额！');history.back();</script>";exit();
}
if($id=='3'){
	$username = $rshy["username"];
	$wp = 6000;
	if($cxprice<6000){
		echo "<script>alert('金额不足');history.back();</script>";exit();
	}
	$fenshu = 1;
	unset($dataArray);
	$dataArray["username"] = $username;
	$dataArray["wp"] = $wp;
	$dataArray["fenshu"] = $fenshu;
	$dataArray["state"] = 1;
	$dataArray['addtime']=$curtime;
	$dataArray['edittime']=0;
	$db->insert("{$db_prefix}cx",$dataArray);
	echo "<script>alert('已提交申请，请等待审核，审核通过后将自动扣取您的金额！');history.back();</script>";exit();
}
if($id=='4'){
	$username = $rshy["username"];
	$wp = 8000;
	if($cxprice<8000){
		echo "<script>alert('金额不足');history.back();</script>";exit();
	}
	$fenshu = 1;
	unset($dataArray);
	$dataArray["username"] = $username;
	$dataArray["wp"] = $wp;
	$dataArray["fenshu"] = $fenshu;
	$dataArray["state"] = 1;
	$dataArray['addtime']=$curtime;
	$dataArray['edittime']=0;
	$db->insert("{$db_prefix}cx",$dataArray);
	echo "<script>alert('已提交申请，请等待审核，审核通过后将自动扣取您的金额！');history.back();</script>";exit();
}
if($id=='5'){
	$username = $rshy["username"];
	$wp = 10000;
	if($cxprice<10000){
		echo "<script>alert('金额不足');history.back();</script>";exit();
	}
	$fenshu = 1;
	unset($dataArray);
	$dataArray["username"] = $username;
	$dataArray["wp"] = $wp;
	$dataArray["fenshu"] = $fenshu;
	$dataArray["state"] = 1;
	$dataArray['addtime']=$curtime;
	$dataArray['edittime']=0;
	$db->insert("{$db_prefix}cx",$dataArray);
	echo "<script>alert('已提交申请，请等待审核，审核通过后将自动扣取您的金额！');history.back();</script>";exit();
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
		
}
td{
font-size:12px;
}
-->
</style>

<link href="images/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" ></td>
    <td width="100%" height="29" valign="top"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">兑换商品</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top"></td>
  </tr>
  <tr>
    <td height="71" valign="middle" >&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="13" valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
                <tr>
                  <td align="center" class="left_bt2">
	  您可以使用的重消余额为：
                                  <?=$rshy['cxmoney']?>
                                人民币/RMB. ￥
</td>
                </tr>
              </table></td>
            </tr>
            <tr>
              <td height="30"><table width="100%" height="60" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
                <tr>
                  <td height="30" align="center" bgcolor="#f2f2f2" >编号</td>
                  <td align="center" bgcolor="#f2f2f2" >兑换商品</td>
               
                  <td height="30" align="center" bgcolor="#f2f2f2" >操作</td>
                  </tr>
				  <tbody bgcolor="#FFFFFF">
	 
                <tr>
                  <td align="center">1</td>
                  <td align="center">兑换商品2000</td>
              
             
                  <td height="30" align="center" ><a href="cx_lst.php?id=1">兑换</a></td>
                  </tr>
				  
                <tr>
                  <td align="center">2</td>
                  <td align="center">兑换商品4000</td>
              
             
                  <td height="30" align="center" ><a href="cx_lst.php?id=2">兑换</a></td>
                  </tr>
				  
                <tr>
                  <td align="center">3</td>
                  <td align="center">兑换商品6000</td>
               
             
                  <td height="30" align="center" ><a href="cx_lst.php?id=3">兑换</a></td>
                  </tr>
				    <tr>
                  <td align="center">4</td>
                  <td align="center">兑换商品8000</td>
           
             
                  <td height="30" align="center" ><a href="cx_lst.php?id=4">兑换</a></td>
                  </tr>
				    <tr>
                  <td align="center">5</td>
                  <td align="center">兑换商品10000</td>
            
             
                  <td height="30" align="center" ><a href="cx_lst.php?id=5">兑换</a></td>
                  </tr>
  </tbody>
              </table></td>
            </tr>
          </table></td>
      </tr>
    </table></td>
	
	
    <td >&nbsp;</td>
  </tr>
  
  <tr>
    <td valign="middle" ></td>
      <td height="17" valign="top" ></td>
    <td ></td>
  </tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="71" valign="middle" >&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="13" valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td height="30">兑换记录
                <table width="100%" height="60" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                  <td height="30" align="center" bgcolor="#f2f2f2" >编号</td>
                  <td align="center" bgcolor="#f2f2f2" >用户名</td>
                  <td align="center" bgcolor="#f2f2f2" >兑换金额</td>
                  <td align="center" bgcolor="#f2f2f2" >状态</td>
                  <td align="center" bgcolor="#f2f2f2" >兑换时间</td> 
                  </tr>
  <?
  $query='';
  if ($action=='query'){
  	
  }
  $sql="select count(id) as c  from {$db_prefix}cx where username='".$_SESSION['sys_username']."'";
  if ($query!='') $sql.=$query;
  $rs=$db->get_one($sql);
  $page=new pagecls(20,intval($rs['c']));
  $sql="select * from {$db_prefix}cx where username='".$_SESSION['sys_username']."'";
  if ($query!='') $sql.=$query;
  $sql.=" order by id desc limit {$page->pastnum},{$page->pagesize}";
  $result=$db->query($sql);
  while($rs=$db->fetch_array($result)){
  ?>
                <tr>
                  <td align="center"><?=$rs['id']?></td>
                  <td align="center" ><?=$rs['username']?></td>
                  <td align="center" ><?=$rs['wp']?></td>
                  <td align="center" class="left_txt3" ><? if ($rs['state']==1) echo "未审核";elseif ($rs['state']==2) echo "已审核";elseif($rs['state']==3) echo "已拒绝";?></td>
                  <td align="center" ><?=date("Y-m-d H:i:s",$rs['addtime'])?></td>
                  </tr>
	<?
  }
  $db->free_result($result);
  ?>
            </table></td>
            </tr>
            
            <tr>
              <td height="30">&nbsp;</td>
            </tr>
            <tr>
              <td height="30" align="right">每页
                <?=$page->pagesize?>
                 第
                <?=$page->pageno?>/<?=$page->pagenum?>
                页 共
                <?=$page->recnum?>                条  <a href='?<?=$page->url?>1'><img src="image1/first.gif" border="0"></a>   <a href='?<?=$page->url.($page->pageno-1)?>'><img src="image1/back.gif" border="0"></a>  <a href='?<?=$page->url.($page->pageno+1)?>'><img src="image1/next.gif" border="0"></a>   <a href='?<?=$page->url.$page->pagenum?>'><img src="image1/last.gif" border="0"></a></td>
              </tr>
            <tr>
              <td height="30">&nbsp;</td>
            </tr>
          </table></td>
      </tr>
    </table></td>
    <td width="17" >&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" ></td>
      <td height="17" valign="top" ></td>
    <td ></td>
  </tr>
</table>
</body>
</html>
